import LoadingComponent from './loading.vue'
let $vm
let Loading = {}
Loading.install = (Vue, options = {}) =>{
  if(!$vm){
    const LoadingPlugin = Vue.extend(LoadingComponent);
    $vm = new LoadingPlugin(options).$mount();
    document.body.appendChild($vm.$el);
  }
  $vm.show = false;
  // let count = -1;
  let count = 0; // 原来值是-1
  let loading = {
    show(title) {
      count++
      if(count<=0){
        $vm.show = false
      } else {
        $vm.show = true
      }
      $vm.text = title
    },
    hide(){
      count--;
      if(count<=0){
        $vm.show = false
      }
    }

  }
  if(!Vue.$loading){
    Vue.$loading = loading;
  }
  Vue.mixin({
    created(){
      this.$loading = Vue.$loading
    }
  })
}
export default Loading
